<?php

namespace App\Logging;

use Monolog\Formatter\LineFormatter;

class CustomFormatter extends LineFormatter
{
    public function __construct(?string $format = null, ?string $dateFormat = null, bool $allowInlineLineBreaks = false, bool $ignoreEmptyContextAndExtra = false)
    {
        // 默认格式："[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n";
        $format = sprintf("%s %s auth:%s %s", "[%datetime%]", REQUEST_ID, auth()->id() ?? 0, "%channel%.%level_name%: %message% %context% %extra%\n");
        $ignoreEmptyContextAndExtra = true;
        parent::__construct($format, $dateFormat, $allowInlineLineBreaks, $ignoreEmptyContextAndExtra);
    }
}